package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface AddressBookMapper {

    /**
     * 新增收货地址
     * @param addressBook
     * @return
     */
    @Insert("insert into address_book values (null,#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName}," +
            "#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault},#{createTime}," +
            "#{updateTime},#{createUser},#{updateUser},0)")

    Integer addAddressBook(AddressBook addressBook);

    /**
     * 显示用户地址列表
     * @param userId
     * @return
     */
    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> findAllAddress(Long userId);

    /**
     * 根据id修改地址
     * @param
     * @return
     */

   Integer updateAddress(AddressBook addressBook);

    /**
     * 数据回显：回显地址
     * @param id
     * @return
     */
    @Select("select * from address_book where id=#{id}")
   AddressBook findAddressById(Long id);

    /**
     * 设置默认地址
     * @param addressBook
     * @return
     */
    @Update("update address_book set is_default=1 where id=#{id}")
    Integer setDefaultAddress(AddressBook addressBook);


    /**
     * 设置为非默认地址
     * @param UserId
     * @return
     */
    @Update("update address_book set is_default=0 where user_id=#{userId}")
    Integer updateDefualt(Long UserId);


    /**
     * 删除地址
     * @param id
     * @return
     */
    @Delete("delete from address_book where id=#{id}")
    Integer deleteAddressBook(Long id);


    /**
     * 根据用户id获取默认地址
     * @param userId
     * @return
     */
    @Select("select * from address_book where user_id = #{userId} and is_default = 1")
    AddressBook getDefaultAddress(Long userId);

}
